package gameLevel.survivalLevel;

import gameBasics.PropertyManager;
import gameLevel.GameLevel;
import gameLevel.GameLevelControl;
import tank.Dir;
import tank.EnemyTank;
import tank.TankType;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Random;

public class EnemyTankThread extends Thread {

    private static final int enemyTankNumInSL = Objects.requireNonNull(PropertyManager.getInt("enemyTankNumOfSL"));
    private final Map<Integer, Integer> mapX = new HashMap<>();
    private final Map<Integer, Integer> mapY = new HashMap<>();
    private final Random random = new Random();

    //无参构造方法
    public EnemyTankThread(){
        mapX.put(0, 10);
        mapX.put(1, 540);
        mapX.put(2, 385);
        mapX.put(3, 495);

        mapY.put(0, 110);
        mapY.put(1, 50);
        mapY.put(2, 385);
        mapY.put(3, 200);
    }

    @Override
    public void run() {
        int selection;

        for(int i = 10; i < enemyTankNumInSL; i++){
            if(GameLevelControl.gameLevel != GameLevel.SURVIVAL) return;

            selection = random.nextInt(4);
            switch (selection){
                case 0 -> new EnemyTank(TankType.ENEMY1, mapX.get((i - 10) % 4), mapY.get((i - 10) % 4), Dir.DOWN).setMovingState(true);
                case 1 -> new EnemyTank(TankType.ENEMY2, mapX.get((i - 10) % 4), mapY.get((i - 10) % 4), Dir.LEFT).setMovingState(true);
                case 2 -> new EnemyTank(TankType.ENEMY3, mapX.get((i - 10) % 4), mapY.get((i - 10) % 4), Dir.RIGHT).setMovingState(true);
                case 3 -> new EnemyTank(TankType.ENEMY4, mapX.get((i - 10) % 4), mapY.get((i - 10) % 4), Dir.RIGHT).setMovingState(true);
            }

            try {
                Thread.sleep(5000);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        }
    }

}
